package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.service.IRoleMenuService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.util.List;

import com.hgxd.result.Result;

import com.hgxd.entity.pojo.SysRoleMenu;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色与菜单对应关系 前端控制器
 * </p>
 *
 * @author fsd
 * @since 2023-10-19
 */
@Api(tags = "")
@RestController
@RequestMapping("/roleMenu")
@CrossOrigin
public class RoleMenuController {
    @Resource(name = "roleMenuServiceImpl")
    private IRoleMenuService roleMenuService;

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result insert(@RequestBody SysRoleMenu roleMenu) {
        return Result.ok(roleMenuService.save(roleMenu));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result update(@RequestBody SysRoleMenu roleMenu) {
        return Result.ok(roleMenuService.updateById(roleMenu));
    }

    /**
     * 根据id删除
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result delete(@PathVariable Integer id) {
        return Result.ok(roleMenuService.removeById(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(roleMenuService.removeByIds(ids));
    }

    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result findAll() {
        return Result.ok(roleMenuService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result findOne(@PathVariable Integer id) {
        return Result.ok(roleMenuService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @GetMapping("/get/page")
    @ApiOperation(value = "", notes = "")
    @ApiImplicitParam(name = "", value = "")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {
        QueryWrapper<SysRoleMenu> queryWrapper = new QueryWrapper<>();
        // 倒序查询
        queryWrapper.orderByDesc("id");
        return Result.ok(roleMenuService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }
}

